home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 52
/
Amiga Format AFCD52 (Issue 136, May 2000).iso
/
-in_the_mag-
/
reader_requests
/
xgtool
/
xgtoolset
/
source
/
xgreset
/
xgreset.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-02-23
|
12KB
|
507 lines
/*
RSXG-Reset
A Bars and Pipes tool for reseting the DB50-XG-board from YAMAHA.
Use it together with the other XG ... .ptool ' s -
© 1998 Alfred & Matthias Faust
The Tool-code based farly on the code for the "pc3.ptool" from Richard
Hagen. That's a very good tool, many thanks to him.
Richard has written his tool with DICE. We altered the code to compile
with the free GNU-C-compiler of the ADE. Especially the part was
transcripted, that place the imagedate in chip-RAM, because the
GNU-C-compiler hasn't as yet a keyword like DICE or other compiler for
this.
This code is released into the Public Domain, and may be freely
distributed in its original form.
It is supplied ``as is'', and comes with no warranty. This program code
was released because it might be useful as a starting point for other
programmers. However, if any damage arises from its use, the original
author and we will not be held liable.
You are free to use and modify this code to your heart's content,
provided you acknowledge me as the original author in any code that you
might distribute which is based largely on this code.
I acknowledge that the design of this tool is influenced strongly by
the example code supplied with the Rules for Tools package. However, I
have made substantial contributions of my own.
Matthias & Alfred Faust
j.k.dax@t-online.de
History:
1.0 (2.12.1998)
Initial Release.
*/
#include "bars.h"
#include "myheader.h" // from R.Hagen
#include <libraries/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <exec/memory.h>
#include <exec/execbase.h>
#include <exec/types.h>
#include <string.h>
#include <intuition/intuition.h>
char version[]="\0$VER:RSXG-Edit 1.0 (2.12.98) © Alfred & Matthias Faust";
#define RSXG_NAME "XG-Reset"
#define RSXG_ID 0x52535847
#define RSXG_TYPE (TOOL_NORMAL | TOOL_NOTPAD)
/* the litte Icon in the pipeline */
UWORD *RSXG=NULL;
static UWORD RSXGdata[] =
{
/* Plane 0 */
0x7FFF,0xFE00,
0x7FFF,0xFE00,
0x6000,0x0600,
0x79FB,0x9E00,
0x7E34,0x7E00,
0x7BC3,0xDE00,
0x7BF3,0xDE00,
0x7A7C,0x5E00,
0x79EF,0x9E00,
0x6600,0x6600,
0x7FFF,0xFE00,
0x7FFF,0xFE00,
/* Plane 1 */
0x0000,0x0200,
0x0000,0x0600,
0x1800,0x1E00,
0x07FF,0xE600,
0x99FF,0x9F00,
0x9A3C,0x5F00,
0x9A4F,0xDF00,
0x9B83,0xDF00,
0x1E6E,0x7E00,
0x1800,0x1E00,
0x1FFF,0xFE00,
0x3FFF,0xFE00,
/* Plane 2 */
0x0000,0x0000,
0x0000,0x0000,
0x1800,0x1800,
0x1FFF,0xF800,
0x1FFF,0xF800,
0x1BFF,0xD800,
0x1BFF,0xD800,
0x1BFF,0xD800,
0x1FFF,0xF800,
0x1E00,0x7800,
0x0000,0x0000,
0x0000,0x0000
};
static struct Image RSXG_image = {
0, 0,
24 , 12 , 3 ,
NULL,
0x1f, 0x00,
NULL
};
//Definitions of the gadgets
#define WRITE_GADGET 1
#define SEND_GADGET 2
//all the gadgets
/* Write to track gadget. */
struct IntuiText RSXGIText1 = {
4, 0, JAM1, 4, 2, NULL, "Write", NULL
};
struct Gadget RSXGGadget1 = {
NULL, 60, 18, 45, 11, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, BOOLGADGET,
NULL, NULL, &RSXGIText1, NULL, NULL, WRITE_GADGET, NULL
};
/* Test gadget. */
struct IntuiText RSXGIText2 = {
4, 0, JAM1, 4, 2, NULL, "Send", NULL
};
struct Gadget RSXGGadget2 = {
&RSXGGadget1, 11, 18, 40, 11, GFLG_GADGHBOX|GFLG_GADGHIMAGE, RELVERIFY|GADGIMMEDIATE, BOOLGADGET,
NULL, NULL, &RSXGIText2, NULL, NULL, SEND_GADGET, NULL
};
//the mainwindowstructure
struct NewWindow RSXGNewWindowStructure1 = {
5, 15,
120, 35,
0, 6,
GADGETDOWN|GADGETUP|CLOSEWINDOW,
WINDOWDRAG|WINDOWDEPTH|WINDOWCLOSE|ACTIVATE|NOCAREREFRESH,
&RSXGGadget2,
NULL,
"XG Reset",
NULL,
NULL,
5, 5,
-1, -1,
CUSTOMSCREEN
};
extern struct ExecBase * SysBase;
struct RSXGTool {
struct Tool tool;
char *resetsysex;
char *xgonsysex;
};
static struct ToolMaster master;
extern struct Functions *functions;
//initial values
static void RSXG_tool_init(struct RSXGTool *tool)
{
tool->tool.touched = TOUCH_INIT;
tool->resetsysex = "F07E7F0901F7";
tool->xgonsysex = "F043104C00007E00F7";
}
static struct Event * __saveds processeventcode(struct Event *event)
{
event->tool = event->tool->next;
return(event);
}
static BOOL lock_clip(struct Clip *clip)
{
Forbid();
if (clip->locked == 0)
{
clip->locked = 1;
Permit();
return TRUE;
}
else
{
Permit();
return FALSE;
}
}
static void unlock_clip(struct Clip *clip)
{
clip->locked = 0;
}
//writes sysex into track
static void __saveds insertsysex(char *buff, short size, struct RSXGTool *tool, const LONG time)
{
struct StringEvent *event;
struct String *string;
event = (struct StringEvent *) (*functions->allocevent)();
if (event)
{
string = (struct String *) (*functions->myalloc)(size + 3, MEMF_CLEAR);
if (string)
{
event->next = NULL;
event->string = string;
memcpy(string->string, buff, size);
string->length = size + 2;
event->type = EVENT_SYSX;
event->status = MIDI_SYSX;
event->time = time;
event->tool = tool->tool.next;
if (lock_clip(&(tool->tool.track->clip)))
{
event->next = (struct StringEvent *)tool->tool.track->clip.events.first;
tool->tool.track->clip.events.first = (struct Event *)(*functions->sorteventlist)(event);
unlock_clip(&(tool->tool.track->clip));
}
else
{
(*functions->freelist)(event);
}
}
}
}
// the routine for sending SysEx-data thru the pipeline
static void __saveds sendsysex(char *buff, short size, struct RSXGTool *tool, const LONG time)
{
struct StringEvent *event;
struct String *string;
event = (struct StringEvent *) (*functions->allocevent)();
if (event)
{
string = (struct String *) (*functions->myalloc)(size + 3, MEMF_CLEAR);
if (string)
{
event->string = string;
memcpy(string->string, buff, size);
string->length = size + 2;
event->type = EVENT_SYSX;
event->status = MIDI_SYSX;
event->time = time;
event->tool = tool->tool.next;
WaitTOF();
(*functions->qevent)(event);
(*functions->myfree)(string);
}
}
}
static void __saveds trans_hx(struct RSXGTool *tool, const LONG time, char *sysx, int sw)
{
LONG size;
int a, b, x, y ;
UBYTE abuf[32];
char chr[4];
char *zbuf = NULL;
struct Event *sysx_event;
//translate sysexbuffer into hex
size = strlen(sysx);
zbuf = (char *)AllocVec(size+2, MEMF_ANY|MEMF_CLEAR);
if(zbuf)
{
CopyMem(sysx, zbuf, size);
b=0;
for(a=0;a < size;a=a+2)
{
chr[0] = zbuf[a];
chr[1] = zbuf[a+1];
x=(isdigit((int)chr[0]))? (chr[0]&0xF) : ((chr[0]&0xDF)-55); //this is the
y=(isdigit((int)chr[1]))? (chr[1]&0xF) : ((chr[1]&0xDF)-55); //the translate-core
abuf[b++] = ((x<<4)|y); //writing with bitmanipulation
}
//send hexdata
FreeVec(zbuf);
if (sw == 0) sendsysex(abuf, b, tool, time);
if (sw == 1) insertsysex(abuf, b, tool, time);
}
}
//to hear the changes
static void send_note(struct RSXGTool *tool, const long time, const UBYTE note)
{
struct NoteEvent *on_event = (struct NoteEvent *)(*functions->allocevent)();
if (on_event)
{
struct NoteEvent *off_event = (struct NoteEvent *)(*functions->allocevent)();
if (off_event)
{
on_event->next =
off_event->next = NULL;
on_event->type =
off_event->type = EVENT_VOICE;
on_event->status = MIDI_NOTEON;
off_event->status = MIDI_NOTEOFF;
on_event->value =
off_event->value = note;
on_event->velocity = 80;
on_event->time = time;
off_event->time = time + 200;
on_event->tool =
off_event->tool = tool->tool.next;
(*functions->qevent)(on_event);
(*functions->qevent)(off_event);
}
else
{
(*functions->freeevent)(on_event);
}
}
}
//the center off all
static void __saveds edittoolcode(struct RSXGTool *tool)
{
struct IntuiMessage *message;
struct Window *window;
LONG class, code, time;
struct Gadget *gadget;
struct NewWindow *newwindow;
int i;
RSXGNewWindowStructure1.Screen = functions->screen;
if (tool->tool.touched & TOUCH_EDIT)
{
RSXGNewWindowStructure1.LeftEdge = tool->tool.left;
RSXGNewWindowStructure1.TopEdge = tool->tool.top;
RSXGNewWindowStructure1.Width = tool->tool.width;
RSXGNewWindowStructure1.Height = tool->tool.height;
}
if (!tool->tool.touched)
{
RSXG_tool_init(tool);
}
newwindow = (struct NewWindow *) (*functions->DupeNewWindow)(&RSXGNewWindowStructure1);
if (!newwindow)
{
return;
}
newwindow->Title = 0;
newwindow->Flags |= BORDERLESS;
newwindow->Flags &= ~0xF;
newwindow->BlockPen = 0;
newwindow->DetailPen = 0;
window = (struct Window *) (*functions->FlashyOpenWindow)(newwindow);
if (!window)
{
return;
}
tool->tool.window = window;
(*functions->EmbossWindowOn)(window, WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG, RSXG_NAME, (short)-1, (short)-1, 0, 0);
(*functions->EmbossOn)(window, WRITE_GADGET, 1);
(*functions->EmbossOn)(window, SEND_GADGET, 1);
send_note(tool, functions->timenow, 60);
for (;;)
{
message = (struct IntuiMessage *) (*functions->GetIntuiMessage)(window);
class = message->Class;
code = message->Code;
gadget = (struct Gadget *) message->IAddress;
class = (*functions->SystemGadgets)(window, class, gadget, code);
ReplyMsg((struct Message *)message);
if (class == CLOSEWINDOW)
{
break;
}
else if (class == GADGETDOWN)
{
const short id = gadget->GadgetID;
switch (id)
{
case WRITE_GADGET:
if ((*functions->areyousure)("write to track ?"))
{
if (!functions->running)
{
if (tool->resetsysex != NULL) trans_hx(tool, 1, tool->resetsysex, 1);
if (tool->xgonsysex != NULL) trans_hx(tool, 384, tool->xgonsysex, 1);
}
}
send_note(tool, time, 60);
break;
case SEND_GADGET:
{
long time = functions->timenow;
trans_hx(tool, functions->timenow, tool->resetsysex, 0);
trans_hx(tool, functions->timenow, tool->resetsysex, 0);
send_note(tool, functions->timenow, 60);
}
default:
break;
}
}
else if (class == GADGETUP)
{
/* Nothing. */
}
}
tool->tool.window = 0;
tool->tool.left = window->LeftEdge;
tool->tool.top = window->TopEdge;
tool->tool.width = window->Width;
tool->tool.height = window->Height;
tool->tool.touched = TOUCH_INIT | TOUCH_EDIT;
(*functions->EmbossOff)(window, WRITE_GADGET);
(*functions->EmbossOff)(window, SEND_GADGET);
(*functions->EmbossWindowOff)(window);
(*functions->FlashyCloseWindow)(window);
(*functions->DeleteNewWindow)(newwindow);
}
//to leave the tool correct
void __saveds removetool()
{
FreeVec(RSXG);
}
//start of the tool
struct ToolMaster * inittoolmaster()
{
int i = 0, bank = 0;
if (!(RSXG=(UWORD *)AllocVec(sizeof (RSXGdata), MEMF_CHIP|MEMF_CLEAR))) return(NULL);
CopyMem(&RSXGdata, RSXG, sizeof (RSXGdata));
RSXG_image.ImageData = RSXG;
memset((char *)&master, 0, sizeof(struct ToolMaster));
master.toolid = RSXG_ID;
master.image = &RSXG_image;
strcpy(master.name, RSXG_NAME);
master.edittool = edittoolcode;
master.processevent = processeventcode;
master.tooltype = RSXG_TYPE;
master.toolsize = sizeof(struct RSXGTool);
master.removetool = removetool;
return(&master);
}